﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Job.Web.Framework;
using Job.Logic.Company;
using Job.Entity;

namespace Job.Web.userControls.Company
{
    public partial class ChangePassword : BaseCtrl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string oldPassword = tbOldPassword.Text; ;
                string newPassword = tbNewPassword1.Text;

                MySession session = new MySession();
                int companyId = session.GetCompanyFromSession().CompanyId;

                CompanyLogic logic = new CompanyLogic();
                JobCompanyInfo info = logic.GetCompanyInfo(companyId);
                if (!info.LoginPswd.Equals(oldPassword))
                {
                    showMessage("输入的旧密码不正确！");
                    return;
                }

                info.LoginPswd = newPassword;
                logic.UpdatePassword(info);

                showMessage("更改密码成功，请记住新密码！");
            }
            catch (Exception ex)
            {
                showMessage("系统内部异常，更改密码失败！");
            }
        }

        private void showMessage(string message)
        {
            this.message.InnerHtml = "<font color='#ff0000'>" + message + "</font>";               
            this.message.Visible = true;
            this.message.Height = "30px";
        }
    }
}